package smile.fu.hibernatetest;

import static org.junit.Assert.*;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

import smile.fu.entity.User;

public class hibernate_link {

	@Test
	public void testLink() {
		Configuration configuration=new Configuration();
		configuration.configure();
		SessionFactory sessionFactory=configuration.buildSessionFactory();
		Session session=sessionFactory.openSession();
		Transaction tx=session.beginTransaction();
		try {
			User user =session.get(User.class, 1);
			System.out.println("ID为："+user.getUid());
			System.out.println("password为："+user.getPassword());
			
		}catch (Exception e) {
			tx.rollback();
			System.out.println("发生错误："+e.getMessage());
		}finally {
			tx.commit();
			session.close();
			sessionFactory.close();
		}
	}

}
